<meta charset="utf-8">
(#) Long vector paths

!!! WARNING: Long vector paths
   This is a warning.

Id
:   `VectorPath`
Summary
:   Long vector paths
Severity
:   Warning
Category
:   Performance
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   3.0.0 (October 2017)
Affects
:   Resource files
Editing
:   This check runs on the fly in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/VectorPathDetector.java)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/VectorPathDetectorTest.java)

Using long vector paths is bad for performance. There are several ways
to make the `pathData` shorter:
* Using less precision
* Removing some minor details
* Using the Android Studio vector conversion tool
* Rasterizing the image (converting to PNG)

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/drawable/my_vector.xml:16:Warning: Very long vector path (1622
characters), which is bad for performance. Considering reducing
precision, removing minor details or rasterizing vector. [VectorPath]
    android:pathData="@string/airplane_mask_clip_path_enabled"/&gt;
                      ---------------------------------------
res/drawable/my_vector.xml:37:Warning: Very long vector path (1623
characters), which is bad for performance. Considering reducing
precision, removing minor details or rasterizing vector. [VectorPath]
    android:pathData="M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.093…
                      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------…
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here are the relevant source files:

`res/drawable/my_vector.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;vector
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:name="root"
  android:width="48dp"
  android:height="48dp"
  android:tint="?attr/colorControlNormal"
  android:viewportHeight="48"
  android:viewportWidth="48"&gt;

  &lt;group
    android:translateX="-1.21595"
    android:translateY="6.86752"&gt;

    &lt;clip-path
      android:name="maskClipPath"
      android:pathData="@string/airplane_mask_clip_path_enabled"/&gt;

    &lt;path
      android:name="crossPath"
      android:pathData="@string/airplane_cross_path"
      android:strokeColor="@android:color/white"
      android:strokeWidth="3.5"
      android:trimPathEnd="0"/&gt;

    &lt;group
      android:translateX="23.481"
      android:translateY="18.71151"&gt;
      &lt;path
        android:fillColor="@android:color/white"
        android:pathData="@string/airplane_path"/&gt;
    &lt;/group&gt;
    &lt;group
      android:translateX="23.481"
      android:translateY="18.71151"&gt;
      &lt;path
        android:fillColor="@android:color/white"
        android:pathData=""/&gt;
    &lt;/group&gt;
  &lt;/group&gt;
&lt;/vector&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/values/paths.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;resources&gt;

  &lt;string name="airplane_path"&gt;
M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z   &lt;/string&gt;
  &lt;string name="airplane_cross_path"&gt;M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z &lt;/string&gt;
  &lt;string name="airplane_mask_clip_path_disabled"&gt;
M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z   &lt;/string&gt;
  &lt;string name="airplane_mask_clip_path_enabled"&gt;
M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z M 37.8337860107,-40.3974914551 c 0,0 -35.8077850342,31.5523681641 -35.8077850342,31.5523681641 c 0,0 40.9884796143,40.9278411865 40.9884796143,40.9278411865 c 0,0 -2.61700439453,2.0938873291 -2.61700439453,2.0938873291 c 0,0 -41.1884460449,-40.9392852783 -41.1884460449,-40.9392852783 c 0,0 -34.6200408936,25.4699249268 -34.6200408936,25.4699249268 c 0,0 55.9664764404,69.742401123 55.9664764404,69.742401123 c 0,0 73.2448120117,-59.1047973633 73.2448120117,-59.1047973633 c 0,0 -55.9664916992,-69.7423400879 -55.9664916992,-69.7423400879 Z   &lt;/string&gt;

&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`res/interpolator/my_interpolator.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;pathInterpolator
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:pathData=""/&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/VectorPathDetectorTest.java)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `VectorPathDetector.testBasic`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Adding the suppression attribute `tools:ignore="VectorPath"` on the
  problematic XML element (or one of its enclosing elements). You may
  also need to add the following namespace declaration on the root
  element in the XML file if it's not already there:
  `xmlns:tools="http://schemas.android.com/tools"`.

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="VectorPath" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'VectorPath'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore VectorPath ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>